# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         demo06
# Description:
# Author:       ASUS
# Date:         2019/3/16
#-------------------------------------------------------------------------------

class Man:
    def helo(self):
        return "helo"

def hello():
    return "hello"

def helo2():
    return "helo2"




if __name__=="__main__":
    m = Man()
    m.name = 'aaa'  # 向对象m动态添加name属性
    print(hasattr(m, "name"))

    print("-------------------")
    age = getattr(m, 'age', 40)  # 从对象m中获取成员age，若不存在，则返回40
    print(age)
    helo1 = getattr(m, 'helo', hello)
    print(helo1())
    print("-------------------")

    setattr(m,'name','bbb')      #有则更新，无则添加，所以在使用这个方法时最好先用hasattr方法判断一下
    print(m.name)
    setattr(m,'helo2',helo2)
    print(m.helo2())



